package com.hexiang.util;

import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class UserCodeShard {

    public static void main(String[] args) {
        List<Long> custList = new ArrayList<>();
        for (long i = 150000000000L; i < 150009999999L; i++) {
            custList.add(i);
        }

        Multimap<Long, Long> dbMultimap = LinkedListMultimap.create();
        Multimap<Long, Long> tableMultimap = LinkedListMultimap.create();

        for (Long custCode : custList) {
            dbMultimap.put(custCode % 8, custCode);

            tableMultimap.put(custCode % 32, custCode);
        }
        System.out.println("--------分库规则--------");
        for (Map.Entry entry : dbMultimap.asMap().entrySet()) {
            Collection collection = (Collection) entry.getValue();
            System.out.println(entry.getKey() + "=" + collection.size());
        }

        System.out.println("--------分表规则--------");
        for (Map.Entry entry : tableMultimap.asMap().entrySet()) {
            Collection collection = (Collection) entry.getValue();
            System.out.println(entry.getKey() + "=" + collection.size());
        }
    }

}